﻿/*
 * Copyright 2009 José David Tuero Rodríguez

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 * */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace AtmosCreator
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            LanguageControl language=null;
            Localizer localizer=null;
            try
            {
                try
                {
                    language = new LanguageControl();
                }
                catch
                {
                    MessageBox.Show("Could not open the language configuration file or the file is corrupt. Creating a default one", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    LanguageControl.CreateDefaultLanguage();
                    try
                    {
                        language = new LanguageControl();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Could not create a default the language configuration file. Closing AtmosCreator", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        throw ex;
                    }
                }
                try
                {
                    localizer = new Localizer("localize\\" + language.Language + ".xml");
                }
                catch 
                {
                    MessageBox.Show("Could not open the language file or the file is corrupt. Defaulting to english", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    try
                    {
                        language.Language = "english";
                        localizer = new Localizer("localize\\english.xml");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Can not open the english language file or the file is corrupt. Closing AtmosCreator", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        throw ex;
                    }
                }
                Application.Run(new FrmMain(localizer));
            }
            catch
            {
                Application.Exit();
            }
            

        }
    }
}
